﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using YArchitech.LIB;
using YJKMaterialStatistic;

namespace YJKWndrStatisticsExcel.FastStatisticTable.CommonForms
{
	public partial class SelectFloorForm : System.Windows.Forms.Form
	{
		public SelectFloorForm(List<Level> levels)
		{
			this.m_Levels = levels;
			this.InitializeComponent();
			for (int i = 0; i < this.m_Levels.Count; i++)
			{
				Level level = this.m_Levels[i];
				DataGridViewRow dataGridViewRow = new DataGridViewRow();
				DataGridViewCheckBoxCell dataGridViewCheckBoxCell = new DataGridViewCheckBoxCell();
				dataGridViewCheckBoxCell.Value = true;
				dataGridViewRow.Cells.Add(dataGridViewCheckBoxCell);
				DataGridViewTextBoxCell dataGridViewTextBoxCell = new DataGridViewTextBoxCell();
				dataGridViewTextBoxCell.Value = level.Name;
				dataGridViewRow.Cells.Add(dataGridViewTextBoxCell);
				DataGridViewTextBoxCell dataGridViewTextBoxCell2 = new DataGridViewTextBoxCell();
				dataGridViewTextBoxCell2.Value = "1";
				dataGridViewRow.Cells.Add(dataGridViewTextBoxCell2);
				dataGridViewRow.Tag = level;
				this.dataGridView1.Rows.Add(dataGridViewRow);
			}
		}

		private void btnSelAll_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
			{
				this.dataGridView1.Rows[i].Cells[0].Value = true;
			}
		}

		private void btnSelNone_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
			{
				this.dataGridView1.Rows[i].Cells[0].Value = false;
			}
		}

		private void btnSelContrary_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
			{
				if (Convert.ToBoolean(this.dataGridView1.Rows[i].Cells[0].Value))
				{
					this.dataGridView1.Rows[i].Cells[0].Value = false;
				}
				else
				{
					this.dataGridView1.Rows[i].Cells[0].Value = true;
				}
			}
		}

		private void SelectFloorForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			if (!string.IsNullOrEmpty(this.strFormCaption))
			{
				this.Text = this.strFormCaption;
			}
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			bool flag = false;
			for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
			{
				if (Convert.ToBoolean(this.dataGridView1.Rows[i].Cells[0].Value))
				{
					Level level = this.dataGridView1.Rows[i].Tag as Level;
					List<ElementId> list = new List<ElementId>();
					list.Add(level.Id);
					StandardLevel standardLevel = new StandardLevel();
					if (this.dataGridView1.Rows[i].Cells[1].Value == null)
					{
						MessageBox.Show("楼层标高不能为空！");
						this.dataGridView1.CurrentCell = this.dataGridView1[1, i];
						return;
					}
					string levelName = this.dataGridView1.Rows[i].Cells[1].Value.ToString();
					standardLevel.LevelName = levelName;
					standardLevel.LevelsId = list;
					if (this.dataGridView1.Rows[i].Cells[2].Value == null)
					{
						MessageBox.Show("输入的数量值无效！");
						this.dataGridView1.CurrentCell = this.dataGridView1[2, i];
						return;
					}
					int num;
					if (!int.TryParse(this.dataGridView1.Rows[i].Cells[2].Value.ToString(), out num) || num < 1)
					{
						MessageBox.Show("输入的数量值无效！");
						this.dataGridView1.CurrentCell = this.dataGridView1[2, i];
						return;
					}
					standardLevel.Count = Convert.ToInt32(this.dataGridView1.Rows[i].Cells[2].Value.ToString());
					standardLevel.StandardId = level.Id;
					this.m_liststandardLevel.Add(standardLevel);
					flag = true;
				}
			}
			if (!flag)
			{
				MessageBox.Show("没有勾选任何项！");
				return;
			}
			base.DialogResult = DialogResult.OK;
		}

		public List<StandardLevel> getStandardLevels()
		{
			return this.m_liststandardLevel;
		}

		private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
		{
		}

		private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
		{
		}

		private List<ViewPlan> m_Views = new List<ViewPlan>();

		public string strFormCaption;

		private List<Level> m_Levels = new List<Level>();

		private List<StandardLevel> m_liststandardLevel = new List<StandardLevel>();
	}
}
